package STUDENT.NGUYENHUUTHANG.STRUCTURE_PROGRAMMING.EXAMPLES;

import java.util.Scanner;

public class tamgiac {

	public static void main(String[] args) {
		String side1 = "";
		String side2 = "";
		String side3 = "";
		double a = 0;
		double b = 0;
		double c = 0;
		boolean check = true;
		System.out.println("Ban hay nhap vao 3 canh cua tam giac:");
		do {

			do {
				System.out.println("Nhap canh a:");
	            
	            side1 = new Scanner(System.in).nextLine();
	            if (side1.equals("") || side1.isEmpty()) {
	                check = false;
	            } else {
	                int demDauCham = 0;
	                for (int i = 0; i < side1.length(); i++) {
	                    if (side1.charAt(i) == '.') {
	                        demDauCham++;
	                    }
	                }
	                if (demDauCham > 1) {
	                    check = false;
	                } else if (side1.charAt(0) == '.') {
	                    check = false;
	                } else {
	                    for (int i = 0; i < side1.length(); i++) {
	                        if (side1.charAt(i) != '.') {
	                            if ((side1.charAt(i) < '0' || side1.charAt(i) > '9')) {
	                                check = false;
	                            }
	                        }
	                    }
	                }
	            }
	            if (check == false) {
	                System.out.println("Moi nhap lai:");
	            }
	            else {
	            	a = Double.parseDouble(side1);
	            }
	        } while (check == false);
			do {
				System.out.println("Nhap canh b:");
	            
	            side2 = new Scanner(System.in).nextLine();
	            if (side2.equals("") || side2.isEmpty()) {
	                check = false;
	            } else {
	                int demDauCham = 0;
	                for (int i = 0; i < side2.length(); i++) {
	                    if (side2.charAt(i) == '.') {
	                        demDauCham++;
	                    }
	                }
	                if (demDauCham > 1) {
	                    check = false;
	                } else if (side2.charAt(0) == '.') {
	                    check = false;
	                } else {
	                    for (int i = 0; i < side1.length(); i++) {
	                        if (side2.charAt(i) != '.') {
	                            if ((side2.charAt(i) < '0' || side2.charAt(i) > '9')) {
	                                check = false;
	                            }
	                        }
	                    }
	                }
	            }
	            if (check == false) {
	                System.out.println("Moi nhap lai:");
	            }
	            else {
	            	b = Double.parseDouble(side2);
	            }
	        } while (check == false);
			do {
				System.out.println("Nhap canh c:");
	            
	            side3 = new Scanner(System.in).nextLine();
	            if (side3.equals("") || side3.isEmpty()) {
	                check = false;
	            } else {
	                int demDauCham = 0;
	                for (int i = 0; i < side3.length(); i++) {
	                    if (side3.charAt(i) == '.') {
	                        demDauCham++;
	                    }
	                }
	                if (demDauCham > 1) {
	                    check = false;
	                } else if (side3.charAt(0) == '.') {
	                    check = false;
	                } else {
	                    for (int i = 0; i < side3.length(); i++) {
	                        if (side3.charAt(i) != '.') {
	                            if ((side3.charAt(i) < '0' || side3.charAt(i) > '9')) {
	                                check = false;
	                            }
	                        }
	                    }
	                }
	            }
	            if (check == false) {
	                System.out.println("Moi nhap lai:");
	            }
	            else {
	            	c = Double.parseDouble(side3);
	            }
	        } while (check == false);
			
			

			if (a + b > c && a + c > b && b + c > a) {
				double P = a + b + c;
				System.out.println("Chu vi tam giac la: " + P);
				double p = P / 2;
				double S = Math.sqrt(p * (p - a) * (p - b) * (p - c));
				System.out.println("Dien tich tam giac la: " + S);
			} else {
				System.out.println("Ban nhap 3 canh khong thoa man mot tam giac! Moi nhap lai!");

			}

		} while (a + b <= c || a + c <= b || b + c < a);

	}

}
